<template>
  <div>
    <el-table :data="list" highlight-current-row>
      <el-table-column
        label="随访项目"
        align="center"
        prop="projectName"
        show-overflow-tooltip
      />
      <el-table-column label="随访时间" align="center" prop="date" />
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="handleUpdate(scope.row)">
            编辑
          </el-button>
          <el-button type="text" size="small" @click="handleDelete(scope.row)">
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="600px"
      append-to-body
      :close-on-click-modal="false"
    >
      <el-form
        ref="followForm"
        :model="followForm"
        :rules="rules"
        label-width="80px"
      >
        <el-form-item label="随访项目" prop="projectId">
          <el-select
            v-model="followForm.projectId"
            placeholder="请选择"
            filterable
            clearable
            style="width: 100%"
          >
            <el-option
              v-for="item in projectList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="随访时间" prop="date">
          <el-date-picker
            v-model="followForm.date"
            type="date"
            placeholder="选择日期"
            value-format="yyyy-MM-dd"
            style="width: 100%"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确定</el-button>
        <el-button @click="cancel">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "TableData",
  data() {
    return {
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        skipCount: 0,
        maxResultCount: 10,
      },
      // 表单校验
      rules: {
        result: [{ required: true, message: "请输入结论", trigger: "blur" }],
      },
      // 表格列表
      list: [
        {
          projectName: "11111",
          date: "222",
        },
        {
          projectName: "11111",
          date: "222",
        },
      ],
      // 表单参数
      followForm: {},
      // 检查项目
      projectList: [
        {
          label: "[未]体格检查",
          value: "1",
          result: "222",
          range: "12",
        },
        {
          label: "[未]体格检查",
          value: "2",
          result: "222",
          range: "12",
        },
        {
          label: "dsdsa",
          value: "3",
          result: "222",
          range: "12",
        },
      ],
    };
  },
  computed: {},
  methods: {
    /** 查询检查项目列表 */
    getList() {
      this.loading = true;
      // listProject(this.queryParams).then((response) => {
      //   this.projectList = response.rows
      //   this.total = response.total
      //   this.loading = false
      // })
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reviewRecordOpen = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.followForm = {
        id: undefined,
        result: undefined,
      };
      this.resetForm("followForm");
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm("是否确认删除？")
        .then(function () {
          // return delProject(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 编辑按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.open = true;
      this.title = "跟随项目";
      // const id = row.id || this.ids
      // getProject(id).then((response) => {
      //   this.form = response.data
      //   this.open = true
      //   this.title = '编辑'
      // })
    },
    /** 提交按钮 */
    submitForm() {
      // this.$refs['form'].validate((valid) => {
      //   if (valid) {
      //     if (this.form.id != null) {
      //       updateProject(this.form).then((response) => {
      //         this.$modal.msgSuccess('编辑成功')
      //         this.open = false
      //         this.getList()
      //       })
      //     } else {
      //       addProject(this.form).then((response) => {
      //         this.$modal.msgSuccess('新增成功')
      //         this.open = false
      //         this.getList()
      //       })
      //     }
      //   }
      // })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm("是否确认删除？")
        .then(function () {
          // return delProject(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
  },
};
</script>

<style>
</style>
